#include "process.h"

double gtotal = 1024.0; // 下载总量
double speed = 1.0;     // 下载速度

typedef void (*callback_t)(double, double); // 上层传输回调函数，减少耦合

void DownLoad(double total, callback_t cb)
{
   double curr = 0.0;
   while(1)
   {
       srand(time(NULL));
       if (curr > total)
       {
           cb(curr, total); // 模拟下载完成，更新进度
           break;
       }
       cb(curr, total);
       curr += SpeedFloat(speed, 20.3); // 模拟下载速度波动
       
   }
}

int main()
{
    printf("download: 20.0MB\n");
    DownLoad(20.0, FlushProcess);
    printf("download: 2000.0MB\n");
    DownLoad(2000.0, FlushProcess);
    printf("download: 100.0MB\n");
    DownLoad(100.0, FlushProcess);
    printf("download: 20000.0MB\n");
    DownLoad(20000.0, FlushProcess);
    return 0;
}
